package reflect.classinfo;

import reflect.entity.Person;

import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;

/**
 * @version 1.0
 * @author:罗苏琴
 * @Date 2024/12/2 下午3:04
 */
public class GetClassConstructorsInfo {
    public static void main(String[] args) {
        //构造参数
        Constructor [] cons= Person.class.getDeclaredConstructors();
        System.out.println("============构造方法展示===========");
        for(Constructor con : cons){
            System.out.println("访问修饰符：");
            int modifier=con.getModifiers();
            if((modifier & Modifier.PUBLIC)==Modifier.PUBLIC){
                System.out.println("public");
            }else if((modifier &Modifier.PROTECTED)==Modifier.PROTECTED){
                System.out.println("protected");
            }else if((modifier & Modifier.PRIVATE) ==Modifier.PRIVATE){
                System.out.println("private");
            }else {
                System.out.println("default(package)");
            }
            System.out.println("参数的个数是："+con.getParameterCount());
            Class [] params=con.getParameterTypes();
            if(params.length==0){
                System.out.println("该构造方法没有参数");
            }else {
                System.out.println("该构造方法参数列表为：");
                for (int i = 0;i<params.length;i++){
                    if(i != 0){
                        System.out.println(",");
                        System.out.println(params[i].getName());
                    }
                }
                System.out.println("---------------------------------------");
            }
        }
    }
}
